<template>
  <div class="pro-order-box" v-loading="loading">
    <el-form ref="fmData" :model="fmData" :rules="rules" v-if="fmData != null">
      <div class="purchas-information">
        <el-card class="box-card">
          <div slot="header" class="unfold-way">
            <p>生产订单</p>
            <div class="button-plan">
              <span
                v-if="
                  fmStatus == 'seeStatus' && $route.query.open !== 'addStatus'
                "
              >
                <el-button
                  @click="btnAdd('view')"
                  type="primary"
                  v-hasPermi="['prs:order:entity:add']"
                  :disabled="option.stripStatus"
                >
                  新增</el-button
                >
              </span>
              <span
                v-if="
                  fmStatus == 'seeStatus' && $route.query.open == 'addStatus'
                "
              >
                <el-button
                  @click="btnAdd('add')"
                  type="primary"
                  v-hasPermi="['prs:order:entity:add']"
                  :disabled="option.stripStatus"
                  v-if="fmStatus == 'seeStatus'"
                >
                  新增</el-button
                >
              </span>
              <span v-if="fmStatus == 'updateStatus'">
                <el-button
                  type="primary"
                  @click="btnSave(fmData)"
                  :disabled="option.btnIsClick || fmStatus !== 'updateStatus'"
                  v-hasPermi="['prs:order:entity:edit']"
                  >保存
                </el-button>
                <el-button type="succes" @click="btnUndo">撤回</el-button>
              </span>
              <span v-if="fmStatus == 'addStatus'">
                <el-button
                  type="primary"
                  v-hasPermi="['prs:order:entity:add']"
                  @click="btnNew(fmData)"
                  :disabled="option.btnIsClick"
                  >保存</el-button
                >
              </span>
              <span>
                <el-button
                  type="succes"
                  v-if="fmStatus == 'seeStatus'"
                  v-hasPermi="['prs:order:entity:edit']"
                  @click="btnEdit"
                  :disabled="
                    fmData.invoiceStatus == '1' || fmStatus !== 'seeStatus'
                  "
                  >编辑</el-button
                >
                <el-button
                  type="succes"
                  v-if="fmStatus == 'addStatus'"
                  @click="btnCancel"
                  >取消</el-button
                >
                <el-button
                  type="success"
                  v-hasPermi="['prs:order:permit']"
                  @click="btnCheck"
                  :disabled="
                    fmStatus !== 'seeStatus' ||
                    fmData.invoiceStatus == '1' ||
                    fmData.invoiceStatus == '2'
                  "
                >
                  审核</el-button
                >
                <el-button
                  type="info"
                  v-hasPermi="['prs:order:revoke']"
                  @click="btnUnCheck"
                  :disabled="
                    fmStatus !== 'seeStatus' ||
                    fmData.invoiceStatus == '0' ||
                    fmData.invoiceStatus == '2'
                  "
                  >反审核
                </el-button>
              </span>
              <span>
                <el-button
                  type="success"
                  plain
                  icon="el-icon-printer"
                  size="mini"
                  @click="objPrinter.handlePrint()"
                  v-hasPermi="['prs:order:print']"
                  v-if="fmStatus == 'seeStatus'"
                  >打印</el-button
                >
                <el-dropdown
                  @command="objOperation.btnOperation($event)"
                  trigger="click"
                  v-hasPermi="['prs:order:operate']"
                  v-if="fmStatus == 'seeStatus' || fmStatus == 'updateStatus'"
                >
                  <el-button type="primary" plain>
                    操作<i class="el-icon-arrow-down el-icon--right"></i>
                  </el-button>
                  <el-dropdown-menu slot="dropdown" class="menu-drop-box">
                    <el-dropdown-item
                      :command="'1'"
                      :class="{ active: stack.commandIndex == '1' }"
                    >
                      <i
                        class="el-icon-check"
                        v-if="stack.commandIndex == '1'"
                      ></i
                      ><span>挂起</span>
                    </el-dropdown-item>
                    <el-dropdown-item
                      :command="'2'"
                      :class="{ active: stack.commandIndex == '2' }"
                    >
                      <i
                        class="el-icon-check"
                        v-if="stack.commandIndex == '2'"
                      ></i
                      ><span>关闭</span>
                    </el-dropdown-item>
                    <el-dropdown-item :command="'3'">
                      <span>生产日期</span>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </span>
              <span>
                <el-button
                  type="text"
                  @click="objHelper.downToggle()"
                  style="padding: 0"
                  >{{ style.downTitle }}</el-button
                >
              </span>
            </div>
          </div>
          <collapseTransition>
            <div class="info-list" v-show="style.isToggle" ref="toggleBox">
              <div class="wn-in-box">
                <div class="list-box" style="z-index: 2; background: #fff">
                  <div class="box-input mt-box">
                    <p>单据编码：</p>
                    <el-form-item>
                      <div class="box-add">
                        <el-input v-model="fmData.prsCode" disabled> </el-input>
                        <el-link
                          @click="objHelper.btnExtend()"
                          type="primary"
                          >{{ style.extendTitile }}</el-link
                        >
                      </div>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>单据日期：</p>
                    <el-form-item prop="invoiceDate">
                      <el-date-picker
                        class="input-data"
                        type="date"
                        :disabled="option.disabledInput"
                        placeholder="选择日期"
                        v-model="fmData.invoiceDate"
                        style="width: 100%"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </div>
                  <div class="box-input blue-color">
                    <p>单据状态：</p>
                    <div class="invoice-box">
                      <span
                        v-if="fmData.invoiceStatus == '0'"
                        style="color: #e6a23c"
                        >{{ fmData.invoiceStatus | getInvoice }}</span
                      >
                      <span
                        v-if="fmData.invoiceStatus == '1'"
                        style="color: #67c23a"
                        >{{ fmData.invoiceStatus | getInvoice }}</span
                      >
                      <span
                        v-if="fmData.invoiceStatus == '2'"
                        style="color: #909399"
                        >{{ fmData.invoiceStatus | getInvoice }}</span
                      >
                    </div>
                  </div>
                  <div class="box-input blue-color">
                    <p>业务状态：</p>
                    <el-form-item prop="workStatus">
                      <el-select
                        v-model="fmData.workStatus"
                        :disabled="option.disabledInput"
                      >
                        <el-option
                          v-for="item in enums.optionsworkStatus"
                          :key="item.dictValue"
                          :label="item.dictLabel"
                          :value="item.dictValue"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>
                </div>

                <div
                  class="list-box"
                  :class="{ 'hide-box-x': style.extendStatus }"
                >
                  <div
                    class="tran-box"
                    :class="{ 'hide-box-w': style.extendStatus }"
                  >
                    <div class="box-input">
                      <p>业务类型：</p>
                      <el-form-item>
                        <el-select
                          v-model="fmData.workType"
                          :disabled="option.wmworkStatus || entryMode"
                          placeholder="请选择"
                          @change="objHelper.workTypeChange($event)"
                        >
                          <el-option
                            v-for="item in enums.optionsworkType"
                            :key="item.dictValue"
                            :label="item.dictLabel"
                            :value="item.dictValue"
                          >
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </div>
                    <div class="box-input">
                      <p>操作员：</p>
                      <el-form-item>
                        <el-input v-model="fmData.userOper" disabled>
                        </el-input>
                      </el-form-item>
                    </div>
                    <div class="box-input">
                      <p>审核员：</p>
                      <el-form-item>
                        <el-input v-model="fmData.userCheck" disabled>
                        </el-input>
                      </el-form-item>
                    </div>
                    <div class="box-input">
                      <p>审核日期：</p>
                      <el-form-item prop="checkDate">
                        <el-date-picker
                          class="input-data"
                          type="date"
                          v-model="fmData.checkDate"
                          style="width: 100%"
                          disabled
                        ></el-date-picker>
                      </el-form-item>
                    </div>
                  </div>
                </div>

                <div class="list-box">
                  <div class="box-input mt-box">
                    <p>计划单号：</p>
                    <el-form-item prop="mpOrderCode">
                      <div class="box-add">
                        <el-input v-model="fmData.mpOrderCode" disabled>
                        </el-input>
                        <el-link
                          v-if="
                            fmStatus == 'addStatus' ||
                            fmStatus == 'updateStatus'
                          "
                          @click="objMaterial.handleImportMaterialSelect()"
                          type="primary"
                          >选择</el-link
                        >
                      </div>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>销售单号：</p>
                    <el-form-item>
                      <el-input type="input" v-model="fmData.ppNumber" disabled>
                      </el-input>
                    </el-form-item>
                  </div>

                  <div class="box-input">
                    <p>订单交期：</p>
                    <el-form-item prop="ppDate">
                      <el-date-picker
                        class="input-data"
                        type="date"
                        v-model="fmData.ppDate"
                        style="width: 100%"
                        disabled
                      ></el-date-picker>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>需求日期：</p>
                    <el-form-item prop="needDate">
                      <el-date-picker
                        class="input-data"
                        type="date"
                        disabled
                        placeholder="选择日期"
                        v-model="fmData.needDate"
                        style="width: 100%"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </div>
                </div>
                <div class="list-box">
                  <div class="box-input mt-box">
                    <p>物料编码：</p>
                    <el-form-item>
                      <div class="box-add">
                        <el-input v-model="fmData.invCode" disabled> </el-input>
                      </div>
                    </el-form-item>
                  </div>
                  <div class="box-input">
                    <p>物料名称：</p>
                    <el-form-item>
                      <div class="inv-merge">
                        <span :title="fmData.invName + fmData.invAttribute"
                          >{{ fmData.invName }} {{ fmData.invAttribute }}</span
                        >
                      </div>
                    </el-form-item>
                  </div>
                  <div class="box-input mt-box" style="margin-top: 7px">
                    <p>生产数量：</p>
                    <el-form-item prop="invQuantity">
                      <div
                        class="box-add"
                        :style="{
                          background:
                            fmStatus == 'seeStatus' ? '#f5f7fa' : '#fff',
                        }"
                      >
                        <el-input
                          v-model="fmData.invQuantity"
                          :disabled="option.disabledInput"
                        >
                        </el-input>
                        <el-link>{{ fmData.unitName }}</el-link>
                      </div>
                    </el-form-item>
                  </div>

                  <div class="box-input">
                    <p>备注信息：</p>
                    <el-form-item prop="remarks">
                      <el-input
                        type="textarea"
                        autosize
                        v-model="fmData.remarks"
                        :disabled="option.disabledInput"
                      >
                      </el-input>
                    </el-form-item>
                  </div>
                </div>
                <div class="list-box" v-if="fmConfig.workshopModel == '1'">
                  <div class="box-input">
                    <p>图纸号：</p>
                    <el-form-item prop="remarks">
                      <el-input type="text" v-model="fmData.drawingNo" disabled>
                      </el-input>
                    </el-form-item>
                  </div>
                  <div class="box-input mt-box">
                    <p>工艺路线：</p>
                    <el-form-item prop="prsProcessName">
                      <div class="box-add">
                        <el-input v-model="fmData.prsProcessName" disabled>
                        </el-input>
                        <el-link
                          v-if="
                            fmStatus == 'addStatus' ||
                            fmStatus == 'updateStatus'
                          "
                          @click="objFilling.processView()"
                          type="primary"
                          >选择</el-link
                        >
                      </div>
                    </el-form-item>
                  </div>
                  <div class="box-input mt-box">
                    <p>生产线：</p>
                    <el-form-item>
                      <div class="box-add">
                        <el-input
                          v-model="fmData.beltline"
                          :disabled="option.disabledInput"
                        >
                        </el-input>
                        <el-link
                          v-if="fmStatus !== 'seeStatus'"
                          @click="objFilling.beltlineView()"
                          type="primary"
                          >选择</el-link
                        >
                      </div>
                    </el-form-item>
                  </div>

                  <div class="box-input">
                    <p>生产日期：</p>
                    <el-form-item prop="arrangeDate">
                      <el-date-picker
                        class="input-data"
                        type="datetime"
                        :disabled="option.disabledInput"
                        placeholder="选择日期"
                        v-model="fmData.arrangeDate"
                        style="width: 100%"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </div>
                  <div class="box-input mt-box">
                    <p>加工时长：</p>
                    <el-form-item prop="duration">
                      <div
                        class="box-add"
                        :style="{
                          background:
                            fmStatus == 'seeStatus' ? '#f5f7fa' : '#fff',
                        }"
                      >
                        <el-input
                          v-model="fmData.duration"
                          :disabled="option.disabledInput"
                        >
                        </el-input>
                        <span style="color: #999999">分钟</span>
                      </div>
                    </el-form-item>
                  </div>
                </div>
              </div>
              <div class="articles-numbers" v-if="fmStatus == 'seeStatus'">
                <el-link
                  type="success"
                  v-hasPermi="['prs:order:next']"
                  @click="btnForward(fmData.prsCode, 'last')"
                  :disabled="option.stripStatus"
                  >上一条
                </el-link>
                <el-link
                  type="success"
                  v-hasPermi="['prs:order:next']"
                  @click="btnForward(fmData.prsCode, 'next')"
                  :disabled="option.stripStatus"
                  >下一条
                </el-link>
              </div>
            </div>
          </collapseTransition>
        </el-card>
      </div>
      <div class="purchas-content">
        <el-card class="box-card">
          <!-- 领料明细 -->
          <div>
            <div class="mb-mbom">
              <div slot="header" class="unfold-way">
                <p>领料明细</p>
                <div style="padding-bottom: 7px">
                  <div>
                    <el-button
                      type="primary"
                      :disabled="
                        fmStatus == 'addStatus' || fmData.invoiceStatus !== '1'
                      "
                      plain
                      icon="el-icon-folder-add"
                      @click="objLink.btnPick()"
                    >
                      领料</el-button
                    >
                  </div>
                </div>
              </div>
              <div class="info-table">
                <div class="table-data link-out-side">
                  <el-table :data="stack.pickData" border style="width: 100%">
                    <el-table-column
                      type="index"
                      width="50"
                      align="center"
                      label="序号"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="ppNumber"
                      label="销售订单号"
                      align="center"
                      width="120"
                    >
                      <template slot-scope="scope">
                        <div>
                          <span
                            v-if="
                              scope.row.ppNumber == '' ||
                              scope.row.ppNumber == null
                            "
                            class="el-icon-minus"
                          ></span>
                          <span v-else>{{ scope.row.ppNumber }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="prsCode"
                      label="单据编码"
                      align="center"
                      width="130"
                    >
                      <template v-slot="scope">
                        <div>
                          <span
                            style="color: #1890ff"
                            @click="
                              objLink.handleViewPick(
                                scope.row.prsCode,
                                scope.row.formConfig
                              )
                            "
                            >{{ scope.row.prsCode }}</span
                          >
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="workStatus"
                      label="单据状态"
                      align="center"
                      width="100"
                    >
                      <template v-slot="scope">
                        <div class="order-status">
                          <span
                            v-if="scope.row.invoiceStatus == '0'"
                            style="color: #e6a23c"
                            >{{ scope.row.invoiceStatus | getInvoice }}</span
                          >
                          <span
                            v-if="scope.row.invoiceStatus == '1'"
                            style="color: #67c23a"
                            >{{ scope.row.invoiceStatus | getInvoice }}</span
                          >
                          <span
                            v-if="scope.row.invoiceStatus == '2'"
                            style="color: #909399"
                            >{{ scope.row.invoiceStatus | getInvoice }}</span
                          >
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="业务状态"
                      align="center"
                      width="120"
                    >
                      <template slot-scope="scope">
                        <div class="piece-box">
                          <el-select
                            class="select-pack"
                            v-model="scope.row.workStatus"
                            placeholder=""
                            disabled
                          >
                            <el-option
                              v-for="item in enums.optionsworkStatus"
                              :key="item.dictValue"
                              :label="item.dictLabel"
                              :value="item.dictValue"
                            >
                            </el-option>
                          </el-select>
                        </div>
                      </template>
                    </el-table-column>

                    <el-table-column
                      prop="prsOrderCode"
                      label="生产单号"
                      align="center"
                      width="120"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="invCode"
                      label="物料编码"
                      width="120"
                      align="center"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="invName"
                      label="物料名称"
                      align="center"
                    >
                      <template v-slot="scope">
                        <div>
                          <span
                            @click="handleDawer(scope.row)"
                            v-if="scope.row.wiQuantity > 0"
                            :style="
                              scope.row.quantity == scope.row.wiQuantity
                                ? 'color: #13ce66'
                                : 'color:#1890ff'
                            "
                            >{{ scope.row.invName }}
                            {{ scope.row.invAttribute }}
                            {{ scope.row.densityCode }}</span
                          >
                          <span
                            @click="handleDawer(scope.row)"
                            v-else
                            style="color: #606266"
                            >{{ scope.row.invName }}
                            {{ scope.row.invAttribute }}
                            {{ scope.row.densityCode }}</span
                          >
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="quantity"
                      label="领用数量"
                      align="center"
                      width="120"
                    >
                      <template v-slot="scope">
                        <div style="text-align: right">
                          <span>{{ scope.row.quantity }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="wiQuantity"
                      label="出库数量"
                      align="center"
                      width="120"
                    >
                      <template v-slot="scope">
                        <div style="text-align: right">
                          <span>{{ scope.row.wiQuantity }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="date"
                      label="单据日期"
                      align="center"
                      width="120"
                    >
                      <template v-slot="scope">
                        <span
                          v-if="
                            scope.row.invoiceDate !== null &&
                            scope.row.invoiceDate !== undefined
                          "
                          >{{
                            objUtils.inMaterTime(scope.row.invoiceDate)
                          }}</span
                        >
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </div>
          </div>
          <!-- 完工明细 -->
          <div style="margin-top: 10px" v-if="fmConfig.workshopModel == '1'">
            <div class="mb-mbom">
              <div slot="header" class="unfold-way">
                <p>完工明细</p>
                <div style="padding-bottom: 7px">
                  <div>
                    <el-button
                      type="primary"
                      :disabled="
                        fmStatus == 'addStatus' || fmData.invoiceStatus !== '1'
                      "
                      plain
                      icon="el-icon-folder-add"
                      @click="objLink.btnProduct()"
                    >
                      报工</el-button
                    >
                  </div>
                </div>
              </div>
              <div class="info-table">
                <div class="table-data link-out-side">
                  <el-table
                    :data="stack.productData"
                    border
                    style="width: 100%"
                  >
                    <el-table-column
                      type="index"
                      width="50"
                      align="center"
                      label="序号"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="ppNumber"
                      label="销售订单号"
                      align="center"
                      width="150"
                    >
                      <template slot-scope="scope">
                        <div>
                          <span
                            v-if="
                              scope.row.ppNumber == '' ||
                              scope.row.ppNumber == null
                            "
                            class="el-icon-minus"
                          ></span>
                          <span v-else>{{ scope.row.ppNumber }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="prsCode"
                      label="单据编码"
                      align="center"
                      width="150"
                    >
                      <template v-slot="scope">
                        <div>
                          <span
                            style="color: #1890ff"
                            @click="
                              objLink.handleViewProduct(
                                scope.row.prsCode,
                                scope.row.formConfig
                              )
                            "
                            >{{ scope.row.prsCode }}</span
                          >
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="workStatus"
                      label="单据状态"
                      align="center"
                      width="100"
                    >
                      <template v-slot="scope">
                        <div class="order-status">
                          <span
                            v-if="scope.row.invoiceStatus == '0'"
                            style="color: #e6a23c"
                            >{{ scope.row.invoiceStatus | getInvoice }}</span
                          >
                          <span
                            v-if="scope.row.invoiceStatus == '1'"
                            style="color: #67c23a"
                            >{{ scope.row.invoiceStatus | getInvoice }}</span
                          >
                          <span
                            v-if="scope.row.invoiceStatus == '2'"
                            style="color: #909399"
                            >{{ scope.row.invoiceStatus | getInvoice }}</span
                          >
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="params.sys_work_status"
                      label="业务状态"
                      align="center"
                      width="100"
                    >
                    </el-table-column>
                    <el-table-column label="仓库" align="center" width="120">
                      <template slot-scope="scope">
                        <div class="piece-box">
                          <el-select
                            class="select-pack"
                            v-model="scope.row.warehouse"
                            placeholder=""
                          >
                            <el-option
                              v-for="item in enums.optionswarehouse"
                              :key="item.code"
                              :label="item.name"
                              :value="item.code"
                            >
                            </el-option>
                          </el-select>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="woCode"
                      label="生产单号"
                      align="center"
                      width="150"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="invCode"
                      label="物料编码"
                      width="150"
                      align="center"
                    >
                    </el-table-column>
                    <el-table-column
                      prop="invName"
                      label="物料名称"
                      align="center"
                    >
                      <template v-slot="scope">
                        <div>
                          <span
                            v-if="scope.row.wiQuantity > 0"
                            :style="
                              scope.row.quantity == scope.row.wiQuantity
                                ? 'color: #13ce66'
                                : 'color:#1890ff'
                            "
                            >{{ scope.row.invName }}
                            {{ scope.row.invAttribute }}
                          </span>
                          <span v-else style="color: #606266"
                            >{{ scope.row.invName }}
                            {{ scope.row.invAttribute }}
                          </span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="invQuantity"
                      label="完工数量"
                      align="center"
                      width="150"
                    >
                      <template v-slot="scope">
                        <div style="text-align: right">
                          <span>{{ scope.row.invQuantity }}</span>
                        </div>
                      </template>
                    </el-table-column>

                    <el-table-column
                      prop="date"
                      label="单据日期"
                      align="center"
                      width="120"
                    >
                      <template v-slot="scope">
                        <span
                          v-if="
                            scope.row.invoiceDate !== null &&
                            scope.row.invoiceDate !== undefined
                          "
                          >{{
                            objUtils.inMaterTime(scope.row.invoiceDate)
                          }}</span
                        >
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </div>
          </div>
        </el-card>
      </div>
    </el-form>
    <!-- 生产日期/数量 -->
    <el-dialog
      title="修改生产日期"
      :visible.sync="option.arrangeDateDialog"
      width="400px"
    >
      <el-form
        ref="formArrangeDate"
        :model="stack.formArrangeDate"
        label-width="80px"
        :rules="rules"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item
              prop="arrangeDate2"
              label="生产日期"
              style="margin-bottom: 15px; position: relative"
            >
              <el-date-picker
                type="datetime"
                placeholder="选择日期"
                v-model="stack.formArrangeDate.arrangeDate"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item
              prop="duration2"
              label="加工时长"
              style="margin-bottom: 15px"
            >
              <el-input v-model="stack.formArrangeDate.duration"> </el-input>
              <span style="position: absolute; right: 15px; color: #999"
                >分钟</span
              >
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="objOperation.arrangeDateChange()"
          >确定</el-button
        >
        <el-button @click="objOperation.arrangeDateCancel()">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 选择引入物料组件 -->
    <selectImportMaterial
      :selectImportMaterialDialog="stack.ImportMaterialStatus"
      :decimal="fmConfig.decimalQuantity"
      @handleImportMaterialSelect="
        objMaterial.handleImportMaterialSelect($event)
      "
      v-if="stack.ImportMaterialStatus"
      @selectImportMaterialClose="objMaterial.selectImportMaterialClose()"
      @handleImportMaterialSuccess="
        objMaterial.handleImportMaterialSuccess(arguments)
      "
    />
    <!-- 选择产线 -->
    <selectBeltline
      :selectBeltlineDialog="stack.prsStatus"
      @handleBeltlineSelect="objFilling.handleBeltlineSelect($event)"
      v-if="stack.prsStatus"
      :workType="fmData.workType"
      :optionsworkType="enums.optionsworkType"
      @selectBeltlineClose="objFilling.selectBeltlineClose()"
    />
    <!-- 选择工艺路线 -->
    <selectProcess
      :selectProcessDialog="stack.processStatus"
      @handleProcessSelect="objFilling.handleProcessSelect($event)"
      v-if="stack.processStatus"
      @selectProcessClose="objFilling.selectProcessClose()"
    />

    <!-- 打印数据 -->
    <PrintPage
      :printData="print.printData"
      :qrCodeValue="print.qrCodeValue"
      v-if="print.printStatus"
      ref="startPrint"
      :title="print.printTitle"
    />
    <div ref="file"></div>
  </div>
</template>

<script>
//接口
import {
  dictMatching, //系统字典
  addBill, //新增单据
  seeBill, //查看单据
  updateBill, //更新单据
  NextBill, //上一条下一条
  examineBill, //审核单据
  examineDeBill, //反审核单据
  moduleParameters,
  billParameters,
  operationBill, //操作
  listBeltline, //产线
  listPick, //领料明细
  listProduct, //完工明细
  listWarehouses,
  operationArrangeDate, //修改生产日期
} from "../../api/order";
//并行请求
import axios from "axios";
//输入是否为数字效验
import { isAccord } from "@/utils/cingsoft";
// 物料选择组件
import selectMaterial from "../../components/Common/selectMaterial.vue";
//选择引入物料组件
import selectImportMaterial from "./selectImportMaterial.vue";
//产线
import selectBeltline from "./selectBeltline.vue";
//工艺路线
import selectProcess from "./selectProcess.vue";
//打印组件
import PrintPage from "../../components/Order/print";
export default {
  data() {
    // 时长输入效验
    var checkOutDuration = (rule, value, callback) => {
      if (!value) {
        return callback(new Error(""));
      }
      if (!isAccord(value)) {
        callback(new Error(""));
      } else {
        callback();
      }
    };

    // 弹框时长输入效验
    var checkOutDuration2 = (rule, value, callback) => {
      if (!this.stack.formArrangeDate.duration) {
        return callback(new Error(""));
      }
      if (!isAccord(this.stack.formArrangeDate.duration)) {
        callback(new Error(""));
      } else {
        callback();
      }
    };

    // 弹框日期效验
    var checkOutArrangeDate2 = (rule, value, callback) => {
      if (!this.stack.formArrangeDate.arrangeDate) {
        return callback(new Error(""));
      } else {
        callback();
      }
    };

    // 数量输入效验
    var checkOutQuantity = (rule, value, callback, param) => {
      if (!value) {
        return callback(new Error(""));
      }
      if (!isAccord(value)) {
        callback(new Error(""));
      } else {
        callback();
      }
    };
    return {
      // 遮罩层
      loading: false,

      //初始化状态
      initialStatus: false,

      // 进入表单模式，有参、无参
      entryMode: false,

      //进入表单参数
      entry: {
        //记录编辑查看物料编码
        seeCode: "",
        //记录当前路由信息用于关闭当前页面
        routeMsg: {},
        // 记录fmConfig,用于是否刷新当前页面,未做
        setConfig: "",
        //记录时间戳,用于是否刷新当前页面
        timeStamp: "",
      },

      //表单状态-addStatus:新增状态,seeStatus:查看状态,updateStatus:编辑状态
      fmStatus: "",

      //数据表单
      fmData: {
        poAttachmentList: [],
      },

      //新增物料信息
      fmItem: {
        invSortId: "", //物料分类
        invCode: "", //物料编码
        invName: "", //物料名称
        invAttribute: "", //型号规格
        unitCode: "", //主计量
        unitName: "", //主计量
        quantity: "", //数量
        amount: "0.00", //采购金额
        pkgRemarks: "",
        qualityRemarks: "",
        densityCode: "",
        needDate: null,
        woDate: null,
        woCode: "", //上游单据
        woUniqueId: 0, //上游物料
        woQantity: "",
        wiQantity: "",
        remarks: "", //备注
      },

      //单据参数信息
      fmConfig: {
        decimalQuantity: "2", //数量小数位数
        decimalPrice: "2", //数量小数位数
        attrMerge: "false", //规格合并
        attrAlias: "型号规格", //规格别名
        sortArrId: [], //料品大类
        feature: "", //物料特性
        fieldHiding: [], //隐藏字段
        bomConfig: "",
        pickConfig: "",
        productConfig: "",
        workshopModel: "",
      },

      // 查询
      query: {
        code: "",
        sortRoot: "",
        type: true,
      },

      //选项
      option: {
        //按钮是否禁用
        btnIsClick: false,
        //输入框是否禁用
        disabledInput: false,
        //业务类型是否可更改
        wmworkStatus: false,
        //上一条下一条状态
        stripStatus: false,
        // 物料信息状态
        parametersStatus: false,
        //生产日期弹框状态
        arrangeDateDialog: false,
      },

      //枚举
      enums: {
        //单据类型
        optionsInvoiceType: [],
        selectInvoiceType: "",
        //业务类型
        optionsworkType: [],
        selectworkType: "",
        //采购部门
        optionsworkDept: [],
        selectworkDept: [],
        //业务状态
        optionsworkStatus: [],
        selectworkStatus: "",
        // 密度单位
        optionsDensityCode: [],
        //产线
        optionsbeltline: [],
      },

      //执行中
      stack: {
        //操作下拉切换
        commandIndex: "",
        //点击选择物料记录下标，用于更新物料信息
        rowIndex: "",
        //物料选择弹框状态
        selectDialog: false,
        // 物料编码搜索下拉状态
        saveIndex: null,
        // 物料编码搜索数据
        basicfileList: [],
        //加工产线
        prsStatus: false,
        // 引入信息
        optionsImportMaterial: [],
        ImportMaterialStatus: false,
        //上传采购合同
        uploadList: [],
        //采购人员
        optionsworkStaff: [],
        selectworkStaff: "",
        //下发生产
        prsDateDialog: false,
        //需求日期
        needDate: null,
        // 已领料数据
        pickData: [],
        //已完工数据
        productData: [],
        //修改生产日期数据
        formArrangeDate: {
          arrangeDate: "",
          duration: "",
          prsCode: "",
          version: "",
          uniqueId: "",
        },
        //工艺路线弹框
        processStatus: false,
      },

      //样式
      style: {
        // 展开收起
        isToggle: true, //状态
        downTitle: "收起", //按钮辩题
        tableHeight: null, //物料信息高度
        // 展开收缩
        extendStatus: false,
        extendTitile: "收缩",
        successHide: false,
      },

      //打印
      print: {
        //打印组件状态
        printStatus: false,
        //打印数据
        printData: {},
        //打印名称
        printTitle: "",
        //二维码内容
        qrCodeValue: "",
        //打印部门
        printWorkDept: [],
      },

      //内存优化
      objMaterial: this.classMaterial(), //物料
      objPrinter: this.classPrinter(), //打印
      objHelper: this.classHelper(), //助手
      objUtils: this.classUtils(), //工具
      objFilling: this.classFilling(), //产线/工艺路线
      objLink: this.classLink(), //关联
      objOperation: this.classOperation(), //操作
      rules: {
        //是否必须输入
        invoiceDate: [
          {
            required: true,
            trigger: "change",
          },
        ],
        invQuantity: [
          {
            validator: checkOutQuantity,
            required: true,
            trigger: "blur",
          },
        ],
        duration: [
          {
            validator: checkOutDuration,
            required: true,
            trigger: "blur",
          },
        ],
        duration2: [
          {
            validator: checkOutDuration2,
            required: true,
            trigger: "blur",
          },
        ],
        arrangeDate2: [
          {
            validator: checkOutArrangeDate2,
            required: true,
            trigger: "change",
          },
        ],
        ppNumber: [
          {
            required: true,
            trigger: "change",
          },
        ],
        arrangeDate: [
          {
            required: true,
            trigger: "change",
          },
        ],
        beltline: [
          {
            required: true,
            trigger: "change",
          },
        ],
        mpOrderCode: [
          {
            required: true,
            trigger: "change",
          },
        ],
        prsProcessCode: [
          {
            required: true,
            trigger: "change",
          },
        ],
      },
    };
  },
  activated() {
    const refresh = this.$store.getters["productionStatus/getCommonRefresh"];
    console.log(refresh);
    if (refresh == true) {
      if (this.fmData.prsCode !== "") {
        this.objLink.getPick(this.fmData.prsCode);
        this.objLink.getProduct(this.fmData.prsCode);
      }
      this.$store.dispatch("productionStatus/setCommonRefresh", false);
    }

    //参数是否有值
    if (this.initialStatus == true) {
      this.initialStatus = false;
      return;
    }
    if (
      (this.entry.timeStamp !== this.$route.query.timeStamp &&
        this.$route.query.open == "addStatus") ||
      this.$route.query.fmConfig !== this.entry.setConfig
    ) {
      this.Initial();
      return;
    }

    if (this.entry.seeCode !== this.$route.query.detailCode) {
      if (
        this.fmStatus == "seeStatus" &&
        this.$route.query.open !== "addStatus"
      ) {
        this.Initial();
        return;
      }
    }

    if (this.entryMode == true) {
      if (this.fmData.workType !== this.$route.query.workType) {
        this.Initial();
      } else if (this.$route.query.workType == "") {
        this.entryMode = false;
        this.Initial();
      }
    } else {
      if (this.$route.query.workType != "") {
        this.entryMode = true;
        this.Initial();
      }
    }
  },

  created() {
    //初始化页面
    this.initialStatus = true;
    this.Initial();
  },
  methods: {
    Initial() {
      // 按钮状态
      this.fmStatus = this.$route.query.open;
      this.entry.setConfig = this.$route.query.fmConfig;
      this.entry.timeStamp = this.$route.query.timeStamp;
      if (this.fmStatus == "addStatus") {
        //新增状态重置表单
        this.objHelper.handleReset();
        this.stack.pickData = [];
        this.stack.productData = [];
      }
      this.getDictionaryType().then(() => {
        this.objHelper.getParameters().then(() => {
          if (this.fmStatus == "seeStatus" || this.fmStatus == "updateStatus") {
            this.entry.seeCode = this.$route.query.detailCode;
            seeBill({
              prsCode: this.entry.seeCode,
            }).then((res) => {
              if (res.code == 200) {
                this.fmData = res.data;
                if (this.fmData.workStatus == "1") {
                  this.stack.commandIndex = "1";
                } else if (this.fmData.workStatus == "2") {
                  this.stack.commandIndex = "2";
                } else {
                  this.stack.commandIndex = "0";
                }
                this.objLink.getPick(this.fmData.prsCode);
                this.objLink.getProduct(this.fmData.prsCode);
                this.stack.uploadList = this.fmData.poAttachmentList;
                this.objUtils.getDecimal();
                if (this.fmStatus == "seeStatus") {
                  this.option.disabledInput = true;
                  this.option.wmworkStatus = true; //编辑状态下业务类型
                } else {
                  this.option.disabledInput = false;
                  if (this.entryMode == true) {
                    this.option.wmworkStatus = true;
                  } else {
                    this.option.wmworkStatus = false;
                  }
                }
              }
            });
          }
        });
      });

      // 路由信息用于关闭页面
      this.entry.routeMsg = this.$route;
      if (
        this.$route.query.workType !== "" &&
        this.$route.query.fmConfig !== ""
      ) {
        this.entryMode = true; //参数有值时
      } else {
        this.entryMode = false; //参数无值时
      }
      this.objMaterial.materialMaxHeight();
    },

    // 获取字典数据
    getDictionaryType() {
      return new Promise((resolve) => {
        const _self = this;
        _self.loading = false;
        //并行请求
        axios
          .all([
            // 单据类型
            dictMatching("prs_invoice_type"),
            // 业务类型
            dictMatching("prs_order_type"),
            // 业务状态
            dictMatching("sys_work_status"),
            //仓库
            listWarehouses(),
          ])
          .then(
            axios.spread(function (
              resIvType,
              resOrderType,
              resWorkStatus,
              resWarehouses
            ) {
              if (
                resIvType.code == 200 &&
                resOrderType.code == 200 &&
                resWorkStatus.code == 200
              ) {
                // 单据类型
                _self.enums.optionsInvoiceType = resIvType.data;
                // 业务类型
                _self.enums.optionsworkType = resOrderType.data;
                //业务状态
                _self.enums.optionsworkStatus = resWorkStatus.data;
                //仓库
                _self.enums.optionswarehouse = resWarehouses.rows;
                //新增状态
                if (_self.fmStatus == "addStatus") {
                  _self.loading = false;
                  _self.fmData.invoiceDate = new Date();
                  _self.fmData.warehouseOper = _self.$store.getters.name;
                }

                // 查看/编辑数据
                if (_self.$route.query.workType == "") {
                  if (_self.fmStatus == "addStatus") {
                    _self.fmData.workType =
                      _self.enums.optionsworkType[0].dictValue;
                  }
                } else {
                  _self.fmData.workType =
                    _self.enums.optionsworkType[
                      _self.$route.query.workType
                    ].dictValue;
                }
                resolve();
              } else {
                _self.msgError("获取信息失败");
              }
            })
          );
      });
    },

    //确定新增
    btnNew(fmData) {
      if (this.fmData.mpOrderCode == "") {
        this.msgError("请选择计划单号");
        return;
      }
      if (this.fmData.invQuantity <= 0) {
        this.msgError("请输入正确的生产数量");
        return;
      }
      this.$refs.fmData.validate((valid) => {
        if (valid) {
          fmData.invoiceDate = this.parseTime(fmData.invoiceDate);
          if (this.$route.query.fmConfig !== undefined) {
            fmData.formConfig = this.$route.query.fmConfig;
          }
          addBill(fmData)
            .then((res) => {
              this.msgSuccess("新增成功");
              // 更新成功不刷新,重新赋值表单数据
              this.option.btnIsClick = true;
              this.fmStatus = "seeStatus";
              this.option.disabledInput = true;
              this.fmData = res.data;
              this.option.wmworkStatus = true;
              this.$store.dispatch("productionStatus/setOrderRefresh", true);
              this.objLink.getPick(this.fmData.prsCode);
              this.objLink.getProduct(this.fmData.prsCode);
              this.objMaterial.materialMaxHeight();
              this.objUtils.getDecimal();
            })
            .catch((err) => {
              this.msgError("新增失败");
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    // 更新保存
    btnSave(fmData) {
      this.$refs.fmData.validate((valid) => {
        if (valid) {
          fmData.invoiceStatus = "0";
          fmData.invoiceDate = this.parseTime(fmData.invoiceDate);
          updateBill(fmData)
            .then((res) => {
              this.msgSuccess("更新成功");
              this.fmStatus = "seeStatus";
              this.option.disabledInput = true;
              this.fmData = res.data;
              this.option.wmworkStatus = true;
              this.$store.dispatch("productionStatus/setOrderRefresh", true);
              this.objLink.getPick(this.fmData.prsCode);
              this.objLink.getProduct(this.fmData.prsCode);
              this.objMaterial.materialMaxHeight();
              this.objUtils.getDecimal();
            })
            .catch((err) => {
              this.msgError("更新失败");
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    //查看->编辑
    btnEdit() {
      this.option.disabledInput = false;
      this.fmStatus = "updateStatus";
      this.option.btnIsClick = false;
      if (this.entryMode == true) {
        this.option.wmworkStatus = true;
      } else {
        this.option.wmworkStatus = false;
      }
      this.objMaterial.materialMaxHeight();
    },

    //查看->新增
    btnAdd(type) {
      if (type == "view") {
        this.$router.push({
          path: "/prs/production/orderadd",
          query: {
            open: "addStatus",
            workType: this.$route.query.workType,
            fmConfig: this.$route.query.fmConfig,
            timeStamp: new Date().getTime(),
          },
        });
      } else {
        this.fmStatus = "addStatus"; //按钮状态为新增
        this.option.disabledInput = false; //输入框可输入
        this.option.btnIsClick = false; //按钮状态为可点击
        this.enums.selectworkDept = ""; //清空采购部门选择
        this.stack.selectworkStaff = ""; //清空采购人员
        this.objHelper.handleReset(); //重置表单默认值

        if (this.entryMode == true) {
          this.option.wmworkStatus = true;
        } else {
          this.option.wmworkStatus = false;
        }
        this.$refs.fmData.clearValidate();
      }
    },

    //撤回
    btnUndo() {
      this.option.disabledInput = true; //是否可编辑
      this.workStatus = true;
      this.fmStatus = "seeStatus";
      this.option.disabledInput = true;
      this.option.wmworkStatus = true;
    },

    //新增->取消
    btnCancel() {
      const self = this;
      self.$store
        .dispatch("tagsView/delView", self.entry.routeMsg)
        .then(({ visitedViews }) => {
          let cancelFun = {
            isActive(route) {
              return route.path === self.$route.path;
            },
            toLastView(visitedViews, view) {
              const latestView = visitedViews.slice(-1)[0];
              if (latestView) {
                self.$router.push(latestView.fullPath);
              } else {
                if (view.name === "Dashboard") {
                  self.$router.replace({
                    path: "/redirect" + view.fullPath,
                  });
                } else {
                  self.$router.push("/");
                }
              }
            },
          };
          if (cancelFun.isActive(this.entry.routeMsg)) {
            cancelFun.toLastView(visitedViews, this.entry.routeMsg);
          }
        });
    },

    // 操作
    classOperation() {
      const self = this;
      return {
        //操作
        btnOperation(value) {
          if (value == "1" || value == "2") {
            let data = {
              prsCode: self.fmData.prsCode,
              workStatus: value,
              version: self.fmData.version,
            };
            operationBill(data).then((res) => {
              if (res.code == 200) {
                self.fmData.workStatus = res.data.workStatus;
                self.stack.commandIndex = res.data.workStatus;
                self.fmData.version = res.data.version;
                self.msgSuccess("状态修改成功");
              }
            });
          } else {
            self.option.arrangeDateDialog = true;
            self.stack.formArrangeDate = {
              arrangeDate: self.fmData.arrangeDate,
              duration: self.fmData.duration,
              prsCode: self.fmData.prsCode,
              version: self.fmData.version,
              uniqueId: self.fmData.uniqueId,
            };
          }
        },
        // 确定修改生产日期
        arrangeDateChange() {
          self.$refs.formArrangeDate.validate((valid) => {
            if (valid) {
              operationArrangeDate(self.stack.formArrangeDate).then((res) => {
                if (res.code == 200) {
                  self.fmData.arrangeDate = res.data.arrangeDate;
                  self.fmData.duration = res.data.duration;
                  self.fmData.version = res.data.version;
                  self.stack.formArrangeDate = {
                    arrangeDate: "",
                    duration: "",
                    prsCode: "",
                    version: "",
                    uniqueId: "",
                  };
                  self.msgSuccess("生产日期修改成功");
                  self.option.arrangeDateDialog = false;
                }
              });
            } else {
              console.log("error submit!!");
              return false;
            }
          });
        },

        //取消修改
        arrangeDateCancel() {
          self.option.arrangeDateDialog = false;
        },
      };
    },

    //审核
    btnCheck() {
      examineBill([
        {
          prsCode: this.fmData.prsCode,
        },
      ]).then((res) => {
        if (res.code == 200) {
          this.fmData.invoiceStatus = "1";
          this.fmData.checkDate = res.data.checkDate;
          this.fmData.userCheck = res.data.userCheck;
          this.$store.dispatch("productionStatus/setOrderRefresh", true);
          this.msgSuccess("审核成功");
        }
      });
    },

    //反审核
    btnUnCheck() {
      this.$confirm("确定撤销审核", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return examineDeBill([
            {
              prsCode: this.fmData.prsCode,
            },
          ]);
        })
        .then((res) => {
          if (res.code == 200) {
            this.fmData.invoiceStatus = "2";
            this.fmData.checkDate = "";
            this.fmData.userCheck = "";
            this.$store.dispatch("productionStatus/setOrderRefresh", true);
            this.msgSuccess("撤销成功");
          }
        });
    },

    // 上一条下一条
    btnForward(code, type) {
      if (type == "next") {
        this.option.stripStatus = true;
        NextBill({
          prsCode: code,
          workType: this.$route.query.workType,
          type: true,
        })
          .then((res) => {
            if (res.code == 200) {
              this.fmData = res.data;
              this.option.parametersStatus = true;
              this.getDictionaryType();
              this.objUtils.getDecimal();
              this.option.stripStatus = false;
              this.objLink.getPick(this.fmData.prsCode);
              this.objLink.getProduct(this.fmData.prsCode);
            }
          })
          .catch((err) => {
            this.option.parametersStatus = true;
            this.option.stripStatus = false;
          });
      } else {
        this.option.stripStatus = true;
        NextBill({
          prsCode: code,
          workType: this.$route.query.workType,
          type: false,
        })
          .then((res) => {
            if (res.code == 200) {
              this.fmData = res.data;
              this.option.parametersStatus = true;
              this.getDictionaryType();
              this.objUtils.getDecimal();
              this.option.stripStatus = false;
              this.objLink.getPick(this.fmData.prsCode);
              this.objLink.getProduct(this.fmData.prsCode);
            }
          })
          .catch((err) => {
            this.option.parametersStatus = true;
            this.option.stripStatus = false;
          });
      }
    },

    //物料信息
    classMaterial() {
      const self = this;
      return {
        // 物料信息最大高度
        materialMaxHeight() {
          if (`${document.documentElement.clientHeight}` - 460 < 400) {
            self.style.tableHeight = 500;
          } else {
            if (self.fmStatus == "seeStatus") {
              self.style.tableHeight =
                `${document.documentElement.clientHeight}` - 455;
            } else {
              self.style.tableHeight =
                `${document.documentElement.clientHeight}` - 435;
            }
          }
        },

        // 选择引入物料
        handleImportMaterialSelect(code, index) {
          self.stack.ImportMaterialStatus = true;
          self.$refs.fmData.clearValidate();
        },

        // 选择引入物料成功
        handleImportMaterialSuccess(list) {
          self.fmData.salesman = list[0].salesman;
          self.fmData.ppNumber = list[0].pp_number;
          self.fmData.ppDate = list[0].pp_date || null;
          self.fmData.needDate = list[0].prs_date;
          self.fmData.invSortId = list[0].inv_sort_id;
          self.fmData.invSortRoot = list[0].inv_sort_root;
          self.fmData.invCode = list[0].inv_code;
          self.fmData.invName = list[0].inv_name;
          self.fmData.unitName = list[0].unit_name;
          self.fmData.unitCode = list[0].unit_code;
          self.fmData.invAttribute = list[0].inv_attribute;
          self.fmData.mpOrderCode = list[0].mp_order_code;
          self.fmData.invQuantity = list[0].surplus;
          self.fmData.remarks = list[0].remarks;
          self.fmData.drawingNo = list[0].drawing_no;
          self.fmData.woQuantity = list[0].surplus;
          self.fmData.woConfig = list[0].form_config;
          self.fmData.woUniqueId = list[0].unique_id;
          self.fmData.woCode = list[0].mp_code;
          self.fmData.woInvoice = list[0].invoice_type;
          self.fmData.woInvoiceId = list[0].invoice_type_id;
          self.fmData.woType = list[0].work_type;
          self.fmData.woTypeId = list[0].work_type_id;
          self.fmData.woDate = list[0].invoice_date;
        },
        // 删除
        deleteList(index) {
          self.$message({
            message: "删除成功",
            duration: 1000,
          });
          self.fmData.prsOrderSalveList.splice(index, 1);
          self.stack.saveIndex = null;
        },

        //关闭引入组件
        selectImportMaterialClose() {
          self.stack.ImportMaterialStatus = false;
        },
      };
    },

    //关联
    classLink() {
      const self = this;
      return {
        //获取领料单
        getPick(code) {
          axios.all([listPick({ prsOrderCode: code })]).then(
            axios.spread(function (resPick) {
              if (resPick.code == 200) {
                self.stack.pickData = resPick.rows;
                self.objUtils.getDecimal();
              }
            })
          );
        },

        // 查看领料单
        handleViewPick(code, formConfig) {
          self.$router.push({
            path: "/prs/production/pickview",
            query: {
              detailCode: code,
              open: "seeStatus",
              workType: "",
              fmConfig: formConfig,
              timeStamp: new Date().getTime(),
            },
          });
        },

        // 新增领料单
        btnPick() {
          self.$router.push({
            path: "/prs/production/pickadd",
            query: {
              open: "addStatus",
              initCode: self.fmData.prsCode,
              workType: self.$route.query.workType,
              fmReferer: "platform",
              fmConfig: self.fmConfig.pickConfig,
              timeStamp: new Date().getTime(),
            },
          });
        },

        //获取完工单
        getProduct(code) {
          axios.all([listProduct({ woCode: code })]).then(
            axios.spread(function (resPick) {
              if (resPick.code == 200) {
                self.stack.productData = resPick.rows;
                self.objUtils.getDecimal();
              }
            })
          );
        },

        // 查看完工单
        handleViewProduct(code, formConfig) {
          self.$router.push({
            path: "/prs/production/productview",
            query: {
              detailCode: code,
              open: "seeStatus",
              workType: "",
              fmConfig: formConfig,
              timeStamp: new Date().getTime(),
            },
          });
        },

        // 新增完工单
        btnProduct() {
          self.$router.push({
            path: "/prs/production/productadd",
            query: {
              open: "addStatus",
              initCode: self.fmData.prsCode,
              workType: self.$route.query.workType,
              fmReferer: "platform",
              fmConfig: self.fmConfig.productConfig,
              timeStamp: new Date().getTime(),
            },
          });
        },
      };
    },

    //  产线/工艺路线
    classFilling() {
      const self = this;
      return {
        //产线
        beltlineView() {
          self.stack.prsStatus = true;
        },
        handleBeltlineSelect(data) {
          //加工产线
          self.fmData.beltline = data.name;
          self.fmData.beltlineId = data.code;
          self.stack.prsStatus = false;
        },
        selectBeltlineClose() {
          self.stack.prsStatus = false;
        },

        //工艺路线
        processView() {
          self.stack.processStatus = true;
        },
        handleProcessSelect(data) {
          console.log(data);
          //工艺编码
          self.fmData.prsProcessCode = data.processCode;
          self.fmData.prsProcessName = data.name;
          self.stack.processStatus = false;
        },
        selectProcessClose() {
          self.stack.processStatus = false;
        },
      };
    },

    //打印
    classPrinter() {
      const self = this;
      return {
        //打印
        handlePrint() {
          let transferData = JSON.parse(JSON.stringify(self.fmData));
          self.print.qrCodeValue = `prs_invoice_type=0&prs_order_type=${transferData.workType}&code=${transferData.prsCode}`;
          //业务类型
          self.enums.optionsworkType.forEach((obj) => {
            if (obj.dictValue == transferData.workType) {
              transferData.workTypeTran = obj.dictLabel + "生产订单";
            }
          });
          //仓库
          self.enums.optionswarehouse.forEach((obj) => {
            if (obj.code == transferData.warehouse) {
              transferData.warehouse = obj.name;
            }
          });
          //业务状态
          self.enums.optionsworkStatus.forEach((obj) => {
            if (obj.dictValue == transferData.workStatus) {
              transferData.workStatus = obj.dictLabel;
            }
          });
          self.print.printData = transferData;
          self.print.printData.printTime = self.parseTime(new Date());
          self.print.printStatus = true;
          setTimeout(() => {
            this.getTitle().then(() => {
              self.$print(self.$refs.startPrint.$refs.print);
            });
          }, 50);
        },
        //获取模块参数中对应的打印标题
        getTitle() {
          return new Promise((resolve) => {
            moduleParameters({
              moduleId: "sys",
            })
              .then((res) => {
                if (res.code == 200) {
                  const obj = res.rows.find((item) => {
                    return item.configKey == "sys.title.print";
                  });
                  self.print.printTitle = obj.configValue;
                  resolve();
                }
              })
              .catch(() => {
                self.msgError("获取模块参数失败");
              });
          });
        },
      };
    },

    //助手
    classHelper() {
      const self = this;
      return {
        //获取单据参数
        getParameters() {
          return new Promise((resolve, reject) => {
            billParameters({
              formPath: self.$route.query.fmConfig,
            }).then((res) => {
              if (res.code == 200) {
                if (res.data["precision.quantity"] !== "null") {
                  self.fmConfig.decimalQuantity =
                    res.data["precision.quantity"];
                }
                if (res.data["inv.attr.merge"] !== "null") {
                  self.fmConfig.attrMerge = res.data["inv.attr.merge"];
                }

                if (res.data["inv.attr.alias"] !== "null") {
                  self.fmConfig.attrAlias = res.data["inv.attr.alias"];
                }
                if (res.data["inv.scope"] !== "null") {
                  let arr = res.data["inv.scope"].split(",");
                  self.fmConfig.sortArrId = arr;
                }
                self.fmConfig.bomConfig = res.data["bom.config"];
                self.fmConfig.pickConfig = res.data["fm.pick.config"];
                self.fmConfig.productConfig = res.data["fm.product.config"];
                self.fmConfig.workshopModel = res.data["workshop.model"];
                self.fmConfig.feature = res.data["inv.feature"];
                setTimeout(() => {
                  self.option.parametersStatus = true;
                }, 50);
                resolve();
              }
            });
          });
        },

        // 业务类型选择
        workTypeChange(value) {
          self.fmData.workType = value;
          self.stack.prsStatus = false;
        },

        //改变计划日期
        needDateChange(value) {
          if (self.fmData.prsOrderSalveList.length > 0) {
            self.fmData.prsOrderSalveList.forEach((item) => {
              item.arrangeDate = value;
            });
          }
        },

        //获取产线
        getProductionLin() {
          self.stack.prsTitle = "加载中...";
          listBeltline({ workType: self.fmData.workType }).then((res) => {
            self.enums.optionsbeltline = res.rows;
            if (self.enums.optionsbeltline.length == 0) {
              self.stack.prsTitle = "无数据";
            } else {
              self.stack.prsTitle = "";
            }
          });
        },

        // 加工产线/生产商（委外厂家）/供方/选择
        handlePoPuPrs(type) {
          if (type == "prs") {
            //加工产线
            this.getProductionLin(); //获取产线
            self.stack.prsStatus = true;
          }
        },

        //选择成功
        successPoPuPrs(data, type) {
          if (type == "prs") {
            //加工产线
            self.fmData.beltline = data.name;
            self.fmData.beltlineId = data.code;
          }
        },

        // 关闭
        handleClosePoPuPrs(type) {
          if (type == "prs") {
            self.stack.prsStatus = false;
          }
        },

        //收起
        downToggle() {
          self.stack.saveIndex = null;
          if (self.style.downTitle == "收起") {
            self.style.downTitle = "展开";
          } else {
            self.style.downTitle = "收起";
          }
          self.style.isToggle = !self.style.isToggle;
          if (self.style.isToggle == false) {
            self.style.tableHeight = parseInt(self.style.tableHeight) + 170;
          } else {
            self.style.tableHeight =
              `${document.documentElement.clientHeight}` - 440;
          }
        },

        //展开收缩
        btnExtend() {
          self.style.extendStatus = !self.style.extendStatus;
          if (self.style.extendStatus == false) {
            setTimeout(() => {
              self.style.extendTitile = "收缩";
            }, 0);
          } else {
            setTimeout(() => {
              self.style.extendTitile = "展开";
            }, 400);
          }
        },

        //点击新增/查看新增重置表单
        handleReset() {
          self.fmData = {
            prsCode: "", //单据编码
            invoiceDate: new Date(), //单据日期
            invoiceStatus: "0", //单据状态
            invoiceType: "0", //单据类型
            workStatus: "0", //业务状态
            workType: "", //业务类型
            formConfig: "",
            userOper: self.$store.getters.name,
            workDept: "", //业务部门
            workStaff: "", //业务人员
            checkDate: "", //审核日期
            needDate: null,
            prsProcessCode: "",
            prsProcessName: "",
            invSortRoot: "",
            invSortId: "",
            invCode: "",
            duration: "",
            invName: "",
            invAttribute: "",
            unitName: "",
            unitCode: "",
            arrangeDate: "",
            invQuantity: "",
            userCheck: "",
            beltline: "",
            beltlineId: "",
            ppNumber: "",
            ppDate: "",
            mpOrderCode: "",
            remarks: "", //备注
            woUniqueId: "",
            woCode: "",
            woDate: null,
            woConfig: "",
            woInvoice: "",
            woInvoiceId: "",
            woType: "",
            woTypeId: "",
            woQuantity: "",
            wiQuantity: "",
            prsOrderSalveList: [],
          };
          self.stack.selectworkStaff = "";
          /* 初始化状态 */
          self.option.disabledInput = false;
          self.workStatus = false;
          self.option.btnIsClick = false;
          self.option.wmworkStatus = false;
          self.enums.selectworkDept = "";
          self.workStaff = "";
          self.stack.needDate = "";
        },
      };
    },

    //工具
    classUtils() {
      const self = this;
      return {
        //格式化用户输入价格单价小数位数
        formatDecimal(index, data) {
          self.stack.rowIndex = index;

          if (
            self.fmData.prsOrderSalveList[index].quantity !== "" &&
            isAccord(self.fmData.prsOrderSalveList[index].quantity)
          ) {
            let quantity = self.fmData.prsOrderSalveList[index].quantity;
            self.fmData.prsOrderSalveList[index].quantity = parseFloat(
              quantity
            ).toFixed(self.fmConfig.decimalQuantity);
          }
        },

        //格式化数量单价金额小数位数
        getDecimal() {
          if (
            self.fmData.invQuantity !== undefined &&
            self.fmData.invQuantity !== null
          ) {
            self.fmData.invQuantity = parseFloat(
              self.fmData.invQuantity
            ).toFixed(self.fmConfig.decimalQuantity);
          }
          if (self.stack.pickData !== null && self.stack.pickData.length > 0) {
            self.stack.pickData.forEach((item) => {
              if (item.quantity !== undefined && item.quantity !== null) {
                item.quantity = parseFloat(item.quantity).toFixed(
                  self.fmConfig.decimalQuantity
                );
              }
              if (item.wiQuantity !== undefined && item.wiQuantity !== null) {
                item.wiQuantity = parseFloat(item.wiQuantity).toFixed(
                  self.fmConfig.decimalQuantity
                );
              }
            });
          }
          if (
            self.stack.productData !== null &&
            self.stack.productData.length > 0
          ) {
            self.stack.productData.forEach((item) => {
              if (item.invQuantity !== undefined && item.invQuantity !== null) {
                item.invQuantity = parseFloat(item.invQuantity).toFixed(
                  self.fmConfig.decimalQuantity
                );
              }
            });
          }
        },

        //时间格式转换
        inMaterTime(date) {
          let time = new Date(date);
          return (
            time.getFullYear() +
            "-" +
            (time.getMonth() + 1) +
            "-" +
            time.getDate() +
            " "
          );
        },
      };
    },
  },

  filters: {
    getInvoice(status) {
      switch (status) {
        case "0":
          return "开立";
          break;
        case "1":
          return "审核";
          break;
        case "2":
          return "退回";
          break;
        default:
          return "无";
      }
    },
  },
  components: {
    selectMaterial,
    selectImportMaterial,
    selectProcess,
    selectBeltline,
    PrintPage,
  },
  watch: {},
};
</script>

<style lang="scss">
.menu-drop-box {
  .el-dropdown-menu__item {
    width: 90px;
    text-align: center;
    position: relative;

    span {
      display: inline-block;
    }

    i {
      position: absolute;
      left: 15px;
      top: 7px;
    }
  }

  .active {
    i,
    span {
      color: #46a6ff;
    }
  }
}

.pro-order-box {
  .mb-mbom {
    padding: 15px 20px 20px 20px;
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    .piece-box {
      i {
        display: none;
      }
    }
    .cell {
      overflow: hidden !important;
    }
  }
  .link-out-side {
    .el-table__row {
      .cell {
        padding: 0px 15px !important;
      }
    }
    .piece-box {
      i {
        display: none;
      }
    }
  }
  .mt-box {
    .el-form-item__content {
      line-height: 32px;
    }
    .is-error .box-add {
      border: 1px solid #fc6a6a;
      box-sizing: border-box;
    }
  }
  .box-add {
    display: flex;
    justify-content: space-between;
    padding: 0 15px;
    width: 210px;
    align-items: center;
    background-color: #f5f7fa;
    border: 1px solid #dfe4ed;
    border-radius: 5px;
    margin-bottom: 2px;
    .el-link {
      height: 20px;
    }

    .el-input__inner {
      width: 145px !important;
      background: none;
      border: none;
      padding-left: 0;
      padding-right: 0;
    }
    .sel-om-code {
      background-color: #f5f7fa;
      border: 1px solid #dfe4ed;
      height: 32px;
      line-height: 32px;
      padding: 0 15px;
      border-radius: 5px;
      width: 175px;
      overflow: hidden;
      span {
        width: 150px;
        overflow-x: auto;
        display: block;
        white-space: nowrap;
      }
    }
  }
  .tran-box {
    width: 310px;
  }
  .hide-box-x {
    transform: translateX(-300px);
    transition: all 0.4s linear;
  }
  .hide-box-w {
    width: 0px;
    transition: width 0.4s linear;
  }
  .hide-box-ox {
    transform: translateX(300px);
    transition: all 0.4s linear;
  }
  .hide-box-ow {
    width: 310px;
    transition: width 0.4s linear;
  }
  .mb-order {
    padding: 15px 20px 20px 20px;
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  }
  .inv-merge {
    background-color: #f5f7fa;
    border: 1px solid #dfe4ed;
    height: 32px;
    line-height: 32px;
    padding: 0 15px;
    border-radius: 5px;
    width: 210px;
    overflow: hidden;
    -webkit-scrollbar {
      display: none;
    }
    span {
      width: 180px;
      overflow-x: auto;
      display: block;
      white-space: nowrap;
    }
  }
  .prs-data {
    display: flex;
    .data-box {
      display: flex;
      margin-right: 15px;
      align-items: center;
      .el-input__icon {
        line-height: 32px !important;
      }
      .date-l {
        width: 160px !important;
      }
      .el-input__inner {
        padding-left: 30px;
      }
      span {
        font-size: 14px;
        display: inline-block;
        margin-right: 10px;
        flex-shrink: 1;
      }
    }
  }
  .el-textarea__inner {
    font-size: 14px;
    color: #303133;
    padding: 5px 10px !important;
  }

  .quality-box {
    p {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 190px;
      margin: 0 5px;
    }
  }
  .drop-menu {
    position: absolute;
    width: 210px;
    box-shadow: 1px 1px 5px 1px #eee;
    max-height: 500px;
    overflow: auto;
    z-index: 9;
    background: #fff;
    left: 70px;
    top: 35px;
    color: #606266;

    p {
      padding: 10px;
      text-align: center;
      width: 100%;
      color: #606266;
    }

    .menu-close {
      position: sticky;
      top: 0;
      width: 210px;
      text-align: right;
      height: 30px;
      background: #fff;
      line-height: 30px;
      border-bottom: 1px solid #eee;

      .search-top {
        display: flex;
        justify-content: space-between;
        align-items: center;

        span {
          font-size: 14px;
          margin-left: 10px;
          color: #606266;
        }
      }

      a {
        padding-right: 10px;
        font-size: 14px;
      }
    }

    .ma-list {
      .list-t {
        text-align: left;
        cursor: pointer;
        border-bottom: 1px solid #eee;
        font-size: 14px;
        padding-top: 5px;
        padding-bottom: 5px;

        &:hover {
          background-color: #f5f7fa;
        }

        .po-content {
          display: flex;
          align-items: center;
        }

        span {
          display: inline-block;
          margin-left: 10px;
          margin-right: 10px;
        }
      }
    }
  }

  .el-textarea.is-disabled .el-textarea__inner {
    color: #333;
  }

  .purchas-information {
    .el-card__body {
      padding: 15px 20px 10px 20px;
    }

    .el-input__inner,
    .el-textarea__inner {
      width: 210px;
    }
  }

  .set-location {
    display: flex;
    align-items: center;

    .location-btn {
      flex-shrink: 1;
      width: 40px;
      margin-right: 5px;
      height: 20px;
    }
  }

  .el-card.is-always-shadow {
    overflow: inherit;
  }

  .unfold-way {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;

    p {
      margin: 0;
      margin-bottom: 8px;
    }
  }

  .con-spec {
    display: flex;
    text-align: center;
    justify-content: center;
    word-wrap: break-word;

    .spec-l {
      padding-right: 2px;

      input {
        text-align: right !important;
      }
    }

    .spec-r {
      input {
        text-indent: 0 !important;
        text-align: left !important;
      }
    }
  }

  .el-radio__input.is-disabled.is-checked .el-radio__inner {
    border-color: #1890ff;
    background: #1890ff;
  }

  .el-radio__input.is-disabled + span.el-radio__label {
    color: #333;
  }

  .info-list {
    .articles-numbers {
      margin-bottom: 5px;
      text-align: right;

      a {
        font-size: 14px;
        margin-left: 15px;
        color: #1890ff;

        &:hover {
          opacity: 0.7;
        }
      }
    }

    .wn-in-box {
      display: flex;
    }

    .list-box {
      .box-input {
        display: flex;
        margin-right: 30px;
        align-items: center;
        margin-bottom: 5px;
        position: relative;

        .input-select {
          margin-left: 5px;
        }

        p {
          flex-shrink: 0;
          width: 70px;
          font-size: 14px;
          margin: 0px;
        }

        .el-input {
          width: auto;
          flex: 1;
        }

        .el-textarea {
          width: 100%;
          flex: 1;
        }

        .drop-menu {
          position: absolute;
          width: 212px;
          box-shadow: 1px 1px 5px 1px #eee;
          max-height: 120px;
          overflow: auto;
          z-index: 9;
          background: #fff;
          left: 70px;
          top: 35px;
          color: #606266;

          p {
            padding: 10px;
            text-align: center;
            width: 100%;
            color: #606266;
          }

          .menu-close {
            position: sticky;
            top: 0;
            width: 212px;
            text-align: right;
            height: 30px;
            background: #fff;
            line-height: 30px;
            border-bottom: 1px solid #eee;

            .search-top {
              display: flex;
              justify-content: space-between;
              align-items: center;

              span {
                font-size: 14px;
                margin-left: 10px;
                color: #606266;
              }
            }

            a {
              padding-right: 10px;
              font-size: 14px;
            }
          }

          .ma-list {
            .list-t {
              text-align: left;
              cursor: pointer;
              border-bottom: 1px solid #eee;
              font-size: 14px;
              padding-top: 5px;
              padding-bottom: 5px;

              &:hover {
                background-color: #f5f7fa;
              }

              .po-content {
                display: flex;
                align-items: center;
              }

              span {
                display: inline-block;
                margin-left: 10px;
                margin-right: 10px;
              }
            }
          }
        }
      }
    }

    .el-input.is-disabled .el-input__inner {
      color: #333;
    }

    .blue-color .is-disabled .el-input__inner {
      color: #1890ff;
    }
  }

  .purchas-content {
    margin-top: 10px;

    .el-table--border {
      border-left: 1px solid #dfe6ec;
    }
    .el-card__body {
      padding: 0;
    }
    .el-textarea__inner {
      border: none;
    }

    .el-textarea.is-disabled .el-textarea__inner {
      background: none;
    }

    .el-table__row td:first-child,
    .has-gutter th:first-child {
      border-left: none;
    }

    .clearfix {
      p {
        margin: 0;
        margin-bottom: 8px;
      }
    }

    .el-card__header {
      padding-right: 20px;
    }

    .el-input__inner {
      height: 31px;
      line-height: 0;
      padding: 0 5px;
      color: #606266;
    }

    .el-input__icon {
      line-height: 0;
    }

    .el-table .cell {
      overflow: inherit;
    }

    .select-name {
      display: flex;
      align-items: center;

      .el-input {
        flex: 1;
      }

      span {
        line-height: 20px;
        margin-left: 5px;
        font-size: 14px;
        margin-right: 5px;
      }
    }

    .table-data {
      .el-table__body-wrapper {
        overflow: auto;

        .cell {
          height: auto !important;
        }
      }

      .el-table .el-table__header-wrapper th,
      .el-table .el-table__fixed-header-wrapper th {
        height: 35px !important;
      }

      .cell {
        padding: 0;
      }

      .el-input--medium .el-input__inner {
        background: none;
        border-color: #fff;
        border-radius: 0;
        padding: 0;
        text-align: center;
      }

      .el-form-item.is-error .el-input__inner,
      .el-form-item.is-error .el-input__inner:focus,
      .el-form-item.is-error .el-textarea__inner,
      .el-form-item.is-error .el-textarea__inner:focus {
        border-color: #ff4949;
      }

      .el-table--enable-row-hover .el-table__body tr:hover > td {
        background: none;
      }

      .el-table--medium th,
      .el-table--medium td {
        padding: 0 !important;
        text-align: center;
      }

      .el-form-item--medium .el-form-item__content {
        line-height: 30px;
      }

      .add-icon {
        margin-top: 5px;
        text-align: center;
      }
    }

    .el-form-item__error {
      padding-top: 0;
      top: 90%;
    }
  }

  .save-btn {
    margin: 20px;

    button {
      width: 200px;
    }
  }

  .el-form-item {
    margin-bottom: 0;
  }

  .button-plan span {
    display: inline-block;

    button {
      margin-left: 10px;
    }
  }

  .invoice-box {
    background-color: #f5f7fa;
    border-color: #dfe4ed;
    width: 100%;
    padding: 0px 15px;
    height: 32px;
    line-height: 27px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    margin-bottom: 3px;
    margin-top: 3px;

    span {
      font-size: 14px;
    }
  }

  .text-right {
    input {
      text-align: right !important;
      padding-right: 10px !important;
    }

    span {
      display: inline-block;
      padding-right: 10px;
      width: 100%;
      text-align: right;
    }
  }

  .select-box {
    position: relative;

    .drop-menu1 {
      position: absolute;
      width: 395px;
      box-shadow: 1px 1px 5px 1px #eee;
      max-height: 300px;
      overflow: auto;
      z-index: 9;
      background: #fff;

      .menu-close {
        position: sticky;
        top: 0;
        width: 380px;
        text-align: right;
        height: 30px;
        background: #fff;
        line-height: 30px;

        .search-top {
          display: flex;
          justify-content: space-between;
          align-items: center;

          span {
            font-size: 14px;
            margin-left: 10px;
          }
        }

        a {
          padding-right: 10px;
        }
      }

      .ma-list {
        margin-bottom: 10px;

        .list-t {
          text-align: left;
          cursor: pointer;
          border-bottom: 1px solid #eee;
          font-size: 14px;

          &:hover {
            background-color: #f5f7fa;
          }

          span {
            display: inline-block;
            margin-left: 10px;
            margin-right: 10px;
          }
        }
      }
    }
  }

  .matrial-box .basicfile-box .cell {
    height: auto !important;
  }

  .el-card__header {
    padding-right: 20px;
  }
}
</style>
